<template>
    <div>
     <h1>新增</h1>
     <table>
        <tr>
            <td>名称</td>
            <td><input type="text" v-model="data.gname"></td>
            <a v-if="!data.gname" style="color: red;">*</a>
        </tr>
        <tr>
            <td>时间</td>
            <td><input type="date" v-model="data.gtime"></td>
        </tr>
        <tr>
            <td>内容</td>
            <td><input type="text" v-model="data.grong"></td>
        </tr>
        <tr>
            <td>类型</td>
            <td>
                <select v-model="data.typeid">
                    <option value="0">请选择</option>
                    <option v-for="s in tytpes" :value="s.typeid">{{s.typename}}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td></td>
            <td><input  type="button" value="提交" @click="Add"></td>
        </tr>
     </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';

const router=useRouter();

const data=ref({
    
  "gid": 0,
  "gname": "",
  "gtime": "",
  "grong": "",
  "typeid": 0

})
onMounted(()=>
{
    getate()
})
const tytpes=ref([{

      "typeid": 0,
    "typename": ""
}

])


const getate=()=>
{
    axios.get("https://localhost:7075/api/type/xia").then(res=>
        {
            tytpes.value=res.data;
        }
    )
}


const Add=()=>
{
    axios.post("https://localhost:7075/api/gong/Add",data.value).then(res=>
        {
            if(res.data>0)
        {
            alert("添加成功");
            router.push({path:"/App"})
        }
        else{
            alert("添加失败");
        }
        }
    )
}

</script>

<style scoped>

</style>